﻿using System;
using QFramework;
using UnityEngine.Rendering;

namespace ProjectSurvival
{
    public class LevelUpItem
    {
        public LevelUpItem(bool isWeapon)
        {
            IsWeapon = isWeapon;
        }

        public bool IsWeapon;
        public string Name { get; private set; }
        public string Key { get; private set; }
        public string IconName { get; private set; }
        public string PairedName { get; private set; }
        public string PairedIconName { get; private set; }
        public string PairedDescription { get; private set; }


        public int MaxLevel { get; private set; }
        public BindableProperty<int> currentLevel { get; set; } = new BindableProperty<int>(0);

        public BindableProperty<bool> Visible { get; set; } = new BindableProperty<bool>(false);

        private Func<int, string> mDescriptionFactory;

        public string Description => mDescriptionFactory(currentLevel.Value + 1);
        // public string Description
        // {
        //     get { return mDescritptionFactory(currentLevel.Value); }
        //     private set{}
        // }


        //是否升级完成
        public bool UpgradeFinish => currentLevel.Value >= MaxLevel;

        private Action<LevelUpItem, int> mOnUpgrade;

        public void Upgrade()
        {
            currentLevel.Value++;
            mOnUpgrade?.Invoke(this, currentLevel.Value);
            
            LevelUpSystem.CheckAllUnlockedFInish();
        }


        public LevelUpItem WithKey(string key)
        {
            Key = key;
            return this;
        }

        public LevelUpItem WithDescription(Func<int, string> descriptionFactory)
        {
            mDescriptionFactory = descriptionFactory;
            return this;
        }

        public LevelUpItem OnUpgrade(Action<LevelUpItem, int> onUpgrade)
        {
            mOnUpgrade += onUpgrade;
            return this;
        }


        public LevelUpItem WithMaxLevel(int maxLevel)
        {
            MaxLevel = maxLevel;
            return this;
        }

        public LevelUpItem WithName(string name)
        {
            Name = name;
            return this;
        }
        public LevelUpItem WithIconName(string iconName)
        {
            IconName = iconName;
            return this;
        }
        public LevelUpItem WithPairedName(string pairedName)
        {
            PairedName = pairedName;
            return this;
        }

        public LevelUpItem WithPairedIconName(string pairedIconName)
        {
            PairedIconName = pairedIconName;
            return this;
        }

        public LevelUpItem WithPairedDescription(string pairedDescription)
        {
            PairedDescription = pairedDescription;
            return this;
        }
    }
}